﻿using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace DeskNote
{
    internal partial class InsertNote : Form
    {

        internal InsertNote()
        {
            InitializeComponent();
            Region = System.Drawing.Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0,
 Width - 1, Height - 1, 20, 20)); // adjust these parameters to get the look you want.

        }

        private void InsertNote_Load(object sender, EventArgs e)
        {
            txtInsert.Focus();
            this.Focus();
        }
        bool append = true;
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.CheckState == CheckState.Checked)
            {
                txtInsert.Multiline = true;
                txtInsert.AcceptsReturn = false;
                append = false;
                LoadFile();
            }
            else
            {
                append = true;
                txtInsert.AcceptsReturn = false;
                //note = txtInsert.Text = string.Empty;
                txtInsert.Multiline = false;
            }
        }

        //string note = string.Empty;
        private void LoadFile()
        {
            txtInsert.Text =  FileIO.Message;
        }



        internal void Savedata()
        {

            if (!string.IsNullOrEmpty(txtInsert.Text.Trim()))
            {
                if (append)
                {
                    FileIO.UpdateMessage = txtInsert.Text.Trim();
                }
                else
                {
                    FileIO.Message = txtInsert.Text.Trim();
                }

            }
            ResetNoteTaker();
        }

        private void txtInsert_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Return))
            {
                e.Handled = true;
            }
            if (e.KeyChar == (char)Keys.Tab)
            {
                //e.Handled = true;
                e.KeyChar = (char)Keys.Enter;
            }
        }

        internal void ResetNoteTaker()
        {
            append = true;
            txtInsert.Text = "";
            checkBox1.CheckState = CheckState.Unchecked;
        }

        private void txtInsert_KeyDown(object sender, KeyEventArgs e)
        {
        }

    }
}

